package com.example.demo;

import java.awt.*;
import java.util.ArrayList;

public class Turret extends GameObject{

    ArrayList<Turret> turretList = new ArrayList<Turret>();
    public Turret turretBlueOne;
    public Turret turretBlueTwo;
    public Turret turretBlueThree;
    public Turret turretBlueBase;
    public Turret turretRedOne;
    public Turret turretRedTwo;
    public Turret turretRedThree;
    public Turret turretRedBase;

    public Turret(GameFrame gameFrame) {
        super(gameFrame);
        setImg("img/turret.png");
        turretList.add(turretBlueOne = new TurretBlue(gameFrame,1860,3790));
        turretList.add(turretBlueTwo = new TurretBlue(gameFrame,2650,3820));
        turretList.add(turretBlueThree = new TurretBlue(gameFrame,3995,3830));
        turretList.add(turretBlueBase = new TurretBlue(gameFrame,1130,3650));
        turretList.add(turretRedOne = new TurretRed(gameFrame,5100,3030));
        turretList.add(turretRedTwo = new TurretRed(gameFrame,5100,2120));
        turretList.add(turretRedThree = new TurretRed(gameFrame,5060,1570));
        turretList.add(turretRedBase = new TurretRed(gameFrame,4850,1100));
    }

    public Turret(GameFrame gameFrame,int x,int y){
        super(gameFrame,x,y);
        setImg("img/turret.png");
        setHp(6000);
        setCurrentHp(getHp());
        setAttackCoolDownTime(1000);
        setDis(300);
    }

    @Override
    public Rectangle getRec() {
        return new Rectangle(getX()-50,getY()-100,100,180);
    }

    @Override
    public void paintSelf(Graphics g) {
        //生命值为0
        if (getCurrentHp()<=0){
            setAlive(false);
            gameFrame.removeList.add(this);
            if (this instanceof TurretBlue){
                gameFrame.blueList.remove(this);
            }else {
                gameFrame.redList.remove(this);
            }
        }else {
            //添加生命值
            if (this instanceof TurretBlue) {
                this.addHp(g, 50, 130, 100, 20, Color.GREEN);
                attack(gameFrame.redList);
            } else {
                this.addHp(g, 50, 130, 100, 20, Color.RED);
                attack(gameFrame.blueList);
            }
            g.drawImage(getImg(), getX() - 50, getY() - 100, null);
            g.fillOval(getX(), getY(), 10, 10);
            g.drawRect(getX() - 50, getY() - 100, 100, 180);
            g.drawOval(getX() - 300, getY() - 300, 600, 600);
        }
    }
}
